package com.pengtu.entity.detect;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.pengtu.utils.MathsUtils;

/**
 * 隧道工程
 * Tunnelspot.
 */
@Entity
@Table(name = "S_Q_DETECT_TUNNELSPOT")
public class TunnelSpot {

	/**
	 * serialVersionUID:TODO
	 * 
	 * @since 1.0.0
	 */

	private static final long serialVersionUID = 1L;
	private String projectId; // 工程
	private Integer countF501;//  衬砌强度﹡抽检点数 
	private Integer passF501;//  衬砌强度﹡合格点数 
	private Integer countF502;//  衬砌厚度﹡抽检点数 
	private Integer passF502;//  衬砌厚度﹡合格点数 
	private Integer countF503;//  净空﹡抽检点数 
	private Integer passF503;//  净空﹡合格点数 
	private Integer countF504;// //锚杆间距及长度抽检点数 
	private Integer passF504;//锚杆间距及长度合格点数 
	private Date reportdate;
	private String remark;
	private SpotReport spotReport;
	private String id;
	private String groupBy;
	private Date createDate; // 创建时间
	
	public TunnelSpot( Long countF501,
			 Long passF501,
			 Long countF502,
			 Long passF502,
			 Long countF503,
			 Long passF503,
			 Long countF504,
			 Long passF504,String groupBy){
		this.countF501 = countF501 == null ? null : countF501.intValue();
		this.passF501 = passF501 == null ? null : passF501.intValue();
		this.countF502 = countF502 == null ? null : countF502.intValue();
		this.passF502 = passF502 == null ? null : passF502.intValue();
		this.countF503 = countF503 == null ? null : countF503.intValue();
		this.passF503 = passF503 == null ? null : passF503.intValue();
		this.countF504 = countF504 == null ? null : countF504.intValue();
		this.passF504 = passF504 == null ? null : passF504.intValue();
		this.groupBy = groupBy;
	}
	public TunnelSpot( Long countF501,
			 Long passF501,
			 Long countF502,
			 Long passF502,
			 Long countF503,
			 Long passF503,
			 Long countF504,
			 Long passF504){
		this.countF501 = countF501 == null ? null : countF501.intValue();
		this.passF501 = passF501 == null ? null : passF501.intValue();
		this.countF502 = countF502 == null ? null : countF502.intValue();
		this.passF502 = passF502 == null ? null : passF502.intValue();
		this.countF503 = countF503 == null ? null : countF503.intValue();
		this.passF503 = passF503 == null ? null : passF503.intValue();
		this.countF504 = countF504 == null ? null : countF504.intValue();
		this.passF504 = passF504 == null ? null : passF504.intValue();
	}
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(length = 48)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(nullable = false, updatable = false, name = "CREATEDATE")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
	@JoinColumn(name = "SID")
	public SpotReport getSpotReport() {
		return spotReport;
	}

	public void setSpotReport(SpotReport spotReport) {
		this.spotReport = spotReport;
	}

	public TunnelSpot() {
	}

	@Column(name = "PID")
	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	@Column(name = "COUNT_F501")
	public Integer getCountF501() {
		return this.countF501;
	}

	public void setCountF501(Integer countF501) {
		this.countF501 = countF501;
	}

	@Column(name = "PASS_F501")
	public Integer getPassF501() {
		return this.passF501;
	}

	public void setPassF501(Integer passF501) {
		this.passF501 = passF501;
	}

	@Column(name = "COUNT_F502")
	public Integer getCountF502() {
		return this.countF502;
	}

	public void setCountF502(Integer countF502) {
		this.countF502 = countF502;
	}

	@Column(name = "PASS_F502")
	public Integer getPassF502() {
		return this.passF502;
	}

	public void setPassF502(Integer passF502) {
		this.passF502 = passF502;
	}

	@Column(name = "COUNT_F503")
	public Integer getCountF503() {
		return this.countF503;
	}

	public void setCountF503(Integer countF503) {
		this.countF503 = countF503;
	}

	@Column(name = "PASS_F503")
	public Integer getPassF503() {
		return this.passF503;
	}

	public void setPassF503(Integer passF503) {
		this.passF503 = passF503;
	}

	@Column(name = "COUNT_F504")
	public Integer getCountF504() {
		return countF504;
	}

	public void setCountF504(Integer countF504) {
		this.countF504 = countF504;
	}

	@Column(name = "PASS_F504")
	public Integer getPassF504() {
		return passF504;
	}

	public void setPassF504(Integer passF504) {
		this.passF504 = passF504;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "REPORTDATE")
	public Date getReportdate() {
		return this.reportdate;
	}

	public void setReportdate(Date reportdate) {
		this.reportdate = reportdate;
	}

	@Column(name = "REMARK", length = 400)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Transient
	public Double getPassrateF501() {
		Double a = MathsUtils.div("2",getPassF501(), getCountF501(), 0.01);
		if(a==0){
			a = null;
		}
		return a;

	}

	@Transient
	public Double getPassrateF502() {
		Double a = MathsUtils.div("2",getPassF502(), getCountF502(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF503() {
		Double a = MathsUtils.div("2",getPassF503(), getCountF503(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Transient
	public Double getPassrateF504() {
		Double a = MathsUtils.div("2",getPassF504(), getCountF504(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}
	
	@Transient
	public double getCountF500() {
		return MathsUtils.sum(getCountF501(), getCountF502(), getCountF503(), getCountF504());
	}

	@Transient
	public double getPassF500() {
		return MathsUtils.sum(getPassF501(), getPassF502(), getPassF503(), getPassF504());
	}

	@Transient
	public double getPassrateF500() {
		if(getCountF500()==0){
			return 0;}
		else {
		return MathsUtils.div("2",getPassF500(),getCountF500(), 0.01);
	}
	}
	@Transient
	public String getGroupBy() {
		return this.groupBy;
	}
}
